home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / PowerPlant / HCmdButtonAttachment 1.1.1 / HCmdButtonAttachment README next >
Encoding:
Text File  |  1997-07-20  |  13.6 KB  |  303 lines  |  [TEXT/CWIE]

  1. /*******************************************************************************\
  2. |                                                                                |
  3. |    HCmdButtonAttachment         ©1997 John C. Daub.  All rights reserved.        |
  4. |                                                                                |
  5. |    John C. Daub                        <mailto:hsoi@eden.com>                    |
  6. |    <http://www.eden.com/~hsoi/>        <http://www.eden.com/~hsoi/prog.html>    |
  7. |                                                                                |
  8. \*******************************************************************************/
  9.  
  10.  
  11. DESCRIPTION
  12. ```````````
  13.  
  14. A Metrowerks PowerPlant® inherited class that gives controls (LControls) a
  15. command-key equivalent.  This allows for more keyboard navigation.  For
  16. example, the traditional "Save before closing?" dialog asks to "Save",
  17. "Cancel" or "Don't Save".  Save is typically the default key (return) and Cancel
  18. the cancel (escape), but there is no keyboard way to hit Don't Save.  Enter
  19. HCmdButtonAttachment.
  20.  
  21. With HCmdButtonAttachment, you can give (almost) any LControl a command-key
  22. shortcut.  You can specify the key to be the first letter/character of the
  23. control's descriptor or it can be a character of your own arbitrary specification.
  24. You can also have the title of the control change to display the shortcut
  25. or not, and do so after a user-configurable amount of time.
  26.  
  27. This archive includes the HCmdButtonAttachment sources, a custom CTYP file
  28. for use with Constructor 2.4 or later, and an example application to demonstrate
  29. the class.
  30.  
  31.  
  32. HOW TO USE HCmdButtonAttachment
  33. ```````````````````````````````
  34.  
  35. Using this class is fairly easy.  Let's go over a few things:
  36.  
  37. -    To make life easier, put the CTYP file (or an alias to it) in the specified
  38.     location to allow Constructor to read in the CTYP at launch time.  This will
  39.     make editing in Constructor easier.
  40.  
  41. -    Launch Constructor and open the sample app's .ppob file.  Open either of the
  42.     'PPob' resources, Show Hierarchy (as this is the only way to view attachments)
  43.     and then open a Property Inspector window for any of the available
  44.     HCmdButtonAttachments.
  45.     
  46.     Let's explain the fields:
  47.     
  48.     Control's PaneID    -    the PaneIDT of the control on which we are to act
  49.     Use Specified Key    -    true = use the specified key
  50.                             false = use the first character of the control descriptor
  51.     Specified Key        -    the specified key to use (ignored if "Use Specified Key"
  52.                             is false).  Even if "Use Specified Key" is false, you MUST
  53.                             fill in something for this value else the LStream ctor
  54.                             can fail.
  55.     Delay                -    amount of time (in ticks) before we would draw the keyboard
  56.                             shortcut in the control title/descriptor
  57.     Draw Shortcut        -    do you wish the shortcut to be drawn in the title or not?
  58.     
  59.     
  60.     I have attempted to demonstrate the variances and purposes of these fields
  61.     throughout the demo.  Examine the demo's 'PPob's more in-depth to see all of
  62.     the variations.
  63.  
  64. -    It is important to remember how attachments work in PowerPlant.  An attachment
  65.     attaches to an LCommander.  Most of your controls are NOT commanders, so this
  66.     attachment actually attaches to the closest supercommander.  e.g. in our example,
  67.     we attach to the LWindow or the LGADialogBox that contains the controls.
  68.     
  69.     You can see how this impacts behavior by again remembering how attachments work
  70.     in PowerPlant, as well as looking at HCmdButtonAttachment::InitCmdButtonAttachment().
  71.  
  72. -    Tho this class inherits from both LAttachment and LPeriodical, the class is an
  73.     attachment for all practical purposes.  It just happens to also repeat.  This is
  74.     a necessary oddity so the drawing of the shortcut can take place.
  75.  
  76. -    The default behavior for drawing the shortcut goes from "Fred" to "Fred cmd-F" (but
  77.     the cmd is actually the cloverleaf).  You can customize this to your own liking
  78.     by subclassing and overriding MungeTitle().
  79.  
  80. -    To use this class doesn't take much more than registering the class (if you will
  81.     be creating it from a stream), adding the source file to your project, and then
  82.     instantiating the object.  I've worked to make it as drop and play as possible.
  83.     
  84.     I have found it easiest to create the attachments in Constructor, but it is
  85.     possible to create on the fly.  I have demonstrated this in the example application.
  86.  
  87. -    When setting the Execute Message of the attachment, be sure to set it to
  88.     msg_KeyPress (814 in PP_Messages.h).  First, this is the message that this attachment
  89.     is to execute upon.  Also, as of this writing, Constructor (2.4.1) could not
  90.     display this message in it's popup menu in the Property Inspector window.  You will
  91.     have to enter "814" yourself. This should be remedied in Constructor 2.4.2
  92.     (part of CodeWarrior Pro 1)
  93.  
  94. -    You can have duplicate "hot keys" for the controls... one control could be cmd-F
  95.     and another also be cmd-F.  But note that when cmd-F is pressed, both of these
  96.     controls will execute.  Depending what you want, that may or may not be desired
  97.     behavior.  (and there really isn't a clean way that I can see to work around this
  98.     issue, aside from just paying attention to what you're programming).
  99.  
  100. -    Be sure when designing your controls that if you have the shortcut drawn, that your
  101.     control will be wide enough to accomidate the larger/longer text string.
  102.  
  103. -    If you wish to use this attachment with a control that doesn't have a descriptor
  104.     (e.g. an icon control like LGAIconButton), be sure to specify a key to use and
  105.     to NOT draw the shortcut.
  106.     
  107. -    Hopefully the rest should be pretty self-explanatory between reading this, the
  108.     source itself, and then the demo.
  109.                             
  110.  
  111. CREDITS
  112. ```````
  113.  
  114. I wrote this because well...I wanted to have something that would do this :)
  115.  
  116. I've seen others do this sort of thing, and they are good implementations,
  117. just not what I wanted for my needs.
  118.  
  119. I would like to thank Greg Bolsinga for allowing me to pick his brain at odd
  120. times while he tried to get work done, as well as seeing his own version of
  121. something like this.
  122.  
  123.  
  124. DISCLAIMER
  125. ``````````
  126.  
  127. This is NOT a product of Metrowerks Corporation.  Please do NOT contact Metrowerks
  128. for help/support of this class/code.  If you need support, please use the contact
  129. information given below.
  130.  
  131.  
  132. LICENSING AND USAGE AGREEMENT
  133. `````````````````````````````
  134.  
  135. John C. Daub (author) grants you, and you accept, a nonexclusive, nontransferable
  136. license to distribute this code for you within your programs and projects.  You may
  137. distribute this code in object code form only and only on magnetic diskettes,
  138. CD-ROM, or other media with your programs into which this code has been
  139. incorporated (if you need to distribute your program by some other medium, please
  140. contact the author).  You agree that this license gives you no title nor rights
  141. of ownership in, of, and/or to this code, and acknowledge that this code
  142. is property of John C. Daub.  This code is NOT in the public domain.
  143.  
  144. Permission is granted to the following organizations to distribute this
  145. code on their CD-ROM collections:
  146.  
  147. Pacific HiTech, Inc            - Info-Mac CD-ROM
  148. Celestin Company            - Apprentice CD
  149. Meterowerks Corporation        - CodeWarrior
  150.  
  151. If you and/or your organization wishes to distribute this code and are
  152. not explicitly listed above, please contact John C. Daub.
  153.  
  154. You may modify the source code, compile it, and incorporate the resulting object
  155. code into your programs.  If you modify the code, you cannot redistribute the
  156. modified code under the same class/code name.  Furthermore, to prevent any
  157. problems and/or infringements, please contact the author prior to redistribution
  158. of any modified code.
  159.  
  160. John C. Daub licenses this code to you on an "AS IS" basis.  John C. Daub makes
  161. no warranties, neither expressed nor implied, regarding this code, its
  162. merchantability, nor its fitness for any purpose.  John C. Daub agrees to make a
  163. reasonable effort to provide written or verbal corrections for any problems
  164. that might be found in this code.
  165.  
  166. Use of this code must be credited in an appropriate manner and location (such
  167. as printed or online documentation and/or About boxes) with the following
  168. credit line:
  169.  
  170.      HCmdButtonAttachment ©1997 John C. Daub.  All rights reserved.
  171.  
  172. If this license is too restrictive with the current law in your state or country,
  173. you should not use this code at all.  Furthermore, if you personally find this
  174. agreement too restrictive or not to your satisfaction, you should not use this
  175. code at all.
  176.  
  177.  
  178. FUTURE
  179. ``````
  180.  
  181. -    v1.1 should allow other alpha-numeric characters to be used (e.g. = , . ).
  182.     However, unprintable characters (e.g. <enter> <Esc>) still cannot be
  183.     displayed.
  184.         
  185.     I'd like to see if I could come up with a technique to allow any "legal"
  186.     keys to be used (kinda like the Mercutio MDEF does).
  187.  
  188. -    Allow more modifier keys to be specified, i.e. shift, option, control (maybe
  189.     caps lock?), if desired.
  190.  
  191. -    Currently the attachment looks to see if command is held down... doesn't care
  192.     about any others.  If you have cmd, fine.  If you have shift, no go.  But
  193.     if you have cmd and shift, it will still work.  I don't know if this is
  194.     something that I'd want to limit or not (i.e use this key and only this
  195.     key).  As things stand now, it probably doesn't matter.  But of course if
  196.     I do allow other key combos, it will have to be an "if and only if"
  197.     situation.
  198.     
  199.     The Finder does allow for this (e.g. cmd-F and cmd-shift-F are the same thing)
  200.     and that makes sense since one could interpret cmd-F to really be cmd-f, and
  201.     that cmd-F implies the need for shift (to make the caps). So it makes sense
  202.     and all that.
  203.     
  204.     And I can't rememeber exactly, but something tells me that a future MacOS
  205.     version (maybe Rhapsody?) will be case sensative. So cmd-F and cmd-f will
  206.     actually be different (and cmd-F will imply shift, and cmd-shift-f is the
  207.     same thing).
  208.     
  209.     Have to wait and see....
  210.  
  211. -    The class can only be used with controls that have text titles/descriptors.
  212.     Controls that are icons don't really work that well here.  You can do it
  213.     (just be sure to specify to NOT draw the shortcut).
  214.     
  215.     But it might be nice to have some sort of mechanism to show the shortcut
  216.     on non-text controls... just a matter of how to accomplish this.
  217.  
  218. -    One shortcoming is that we draw the command key based upon the given font.
  219.     Very few fonts from what I've seen actually map char_Propeller (0x11) to
  220.     a printable "cloverleaf".  Most either implement nothing (e.g. that
  221.     empty box) or implement something that is nothing (e.g. just is blank).
  222.     Chicago has it, Truth has it... but things like Geneva don't have it.
  223.     
  224.     So this limits the class by forcing you to use a font like Chicago or
  225.     preferably the "System" font... but not everyone wants to do that.  That's
  226.     part of the reason why I broke the title munging routine out for
  227.     easy modification.....
  228.     
  229.     But I just don't know what would be an adequate way to get around this
  230.     (aside from telling font authors to implement the full character suite)....
  231.     and I would like to avoid a Window-ish underlining of the given character.
  232.     
  233.     Typically you can work around this by not drawing the shortcut... just
  234.     let the command be there (e.g. by first letter of the button text or
  235.     some such)
  236.     
  237.  
  238. CONTACT INFORMATION
  239. ```````````````````
  240.  
  241. Even though you don't need to send me email or register or anything to
  242. use the code, it would still be nice to drop me a line and let me know
  243. what you think.  If you find any bugs or add any cool features, send them
  244. to me so I can add it to the official distribution. Furthermore, if I
  245. have your contact information, I can notify you when new versions are
  246. released -- can be very handy if say there is a fatal crashing bug
  247. in the code or some such. So, it's probably in your own best interest
  248. to drop me a line :-)
  249.  
  250. Also, be sure to visit my web site
  251.  
  252. <http://www.eden.com/~hsoi/prog.html>
  253.  
  254. and "register". I won't know if you're "registered" or not, but it's a nice
  255. way that you can be notified of product updates (e.g. I make a new
  256. version, post it on that page, if you're registered, you'll be emailed
  257. automatically that the page changed).
  258.  
  259. John C. Daub
  260. <mailto:hsoi@eden.com>
  261. <http://www.eden.com/~hsoi/prog.html>
  262.  
  263.  
  264. CHANGE HISTORY
  265. ``````````````
  266.  
  267. Date        Vers    Who        Notes
  268. ----------------------------------------------------------------------------
  269. 22 Apr 97    1.0        JCD        - Created and initial release
  270.  
  271. 24 Jun 97    1.1        JCD        - Removed the hyphen from MungeTitle(). Makes the shortcut
  272.                             look the same as in MENUs and such.
  273.                             - Restructured class declaration (ordering of data members)
  274.                             (I heard struct alignment affects classes as well...)
  275.                             - FindHotKey() only calls UppercaseText() if theHotKey is between
  276.                             'a' and 'z'...saves a bit of a call, and should also allow
  277.                             non-alphanumeric keys to be used
  278.                             - Updated licensing agreement.
  279.                             - Upgraded to CW Pro1.
  280.                             - Can compile with no precompiled headers now.
  281.                             - Cleaned up sources for improved readability.
  282.  
  283. 15 Jul    97    1.1.1    JCD        - All ctor's use initialization lists instead of
  284.                             assignment (where possible).
  285.                             - All member data is now private (was protected). Appropriate
  286.                             accessor functions have been created (as public or
  287.                             protected, depending on context). Helps to further abstract
  288.                             the user away from the data (good C++ style).
  289.                             - Added include for PowerPlant_PCH to be consistant with
  290.                             PowerPlant sources.
  291.                             - Inline functions no longer defined within class declaration.
  292.                             Definitions moved outside of the class, but still in the header
  293.                             file. #pragma mark's added to source file to ease navigation
  294.                             and user indexing.
  295.                             - In SpendTime() the call to FindHotKey moved from outside the
  296.                             if-else statement to inside the statement just before MungeTitle
  297.                             is called (saves calling this routine if not needed, e.g. the
  298.                             else-statement).
  299.                             - In InitCmdButtonAttachment, we got the control's original title.
  300.                             If we failed, mOriginalTitle was assigned a nil string. But this
  301.                             is unnecessary as mOrignialTitle is set to nil in the ctor's and
  302.                             not otherwise modified. Saves a decent amount of code-gen size.
  303.                             - Demo's GA dialog now has attachments for Cancel and OK buttons.